package com.exhibition.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.exhibition.service.ITbSampleTypeService;
import com.exhibition.util.Util;

@Controller
public class TbSampleTypeController {
	
	@Autowired
	ITbSampleTypeService tbSampleTypeService;
	
	@RequestMapping("admin/typeList.do")	
	public ModelAndView list(HttpServletRequest request,String type_name){
		ModelAndView mav=new ModelAndView("./type/list.jsp");
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("type_name", type_name);
		mav.addObject("list", tbSampleTypeService.getList(map));
		mav.addObject("type_name", type_name);
		return mav;
	}
	@RequestMapping("admin/typeAddOk.do")	
	public ModelAndView addOk(HttpServletRequest request,
			String type_name){
		ModelAndView mav=new ModelAndView("redirect:/admin/typeList.do");
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("type_id", Util.getPrimaryKey());
		map.put("type_name", type_name);
		tbSampleTypeService.add(map);
		return mav;
	}
	
	@RequestMapping("admin/typeUpdate.do")	
	public ModelAndView update(HttpServletRequest request,String type_id){
		ModelAndView mav=new ModelAndView("./type/update.jsp");
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("type_id", type_id);
		mav.addObject("type", tbSampleTypeService.getOne(map));
		return mav;
	}
	@RequestMapping("admin/typeUpdateOk.do")	
	public ModelAndView updateOk(HttpServletRequest request,
			String type_id,
			String type_name
			){
		ModelAndView mav=new ModelAndView("redirect:/admin/typeList.do");
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("type_id", type_id);
		map.put("type_name", type_name);
		tbSampleTypeService.update(map);
		return mav;
	}
	@RequestMapping("admin/typeDelete.do")	
	public ModelAndView delete(HttpServletRequest request,String type_id){
		ModelAndView mav=new ModelAndView("redirect:/admin/typeList.do");
		tbSampleTypeService.delete(type_id);
		return mav;
	}
}
